cmake_minimum_required(VERSION 3.0.2)
project(diff_drive_robot)

## 使用C++11标准编译，ROS Kinetic及更高版本支持
add_compile_options(-std=c++11)

## 查找catkin宏和库
find_package(catkin REQUIRED COMPONENTS
  controller_manager
  hardware_interface
  joint_state_controller
  roscpp
  rospy
  std_msgs
  urdf
  ros_control_boilerplate
  diff_drive_controller
)

## 声明catkin包
catkin_package(
  INCLUDE_DIRS include
  LIBRARIES diff_drive_robot
  CATKIN_DEPENDS controller_manager hardware_interface joint_state_controller roscpp rospy std_msgs urdf ros_control_boilerplate diff_drive_controller
)

## 指定头文件的额外位置
include_directories(
  include
  ${catkin_INCLUDE_DIRS}
)

## 声明C++库
add_library(diff_drive_robot
  src/diff_drive_hardware_interface.cpp
)

## 添加库的cmake目标依赖项
add_dependencies(diff_drive_robot ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## 指定库或可执行目标链接的库
target_link_libraries(diff_drive_robot
  ${catkin_LIBRARIES}
)

## 标记可执行文件和/或库以便安装
install(TARGETS diff_drive_robot
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
)

install(DIRECTORY include/${PROJECT_NAME}/
  DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
)

## 声明节点可执行文件
add_executable(diff_drive_hardware_interface_node src/diff_drive_hardware_interface_node.cpp)

add_dependencies(diff_drive_hardware_interface_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(diff_drive_hardware_interface_node
  diff_drive_robot
  ${catkin_LIBRARIES}
)
